<template>
    <span>
        <Drawer title="教育经历" :closable="false" placement="right" v-model="edu" width="60%">
            <Row>
                <Table :loading="loading" border :columns="columns" :data="data" sortable="custom" @on-sort-change="changeSort" @on-selection-change="showSelect" ref="table"></Table>
            </Row>
            <Row type="flex" justify="end" class="page">
                <Page :current="searchForm.pageNumber" :total="total" :page-size="searchForm.pageSize" @on-change="changePage" @on-page-size-change="changePageSize" :page-size-opts="[10,20,50]" size="small" show-total show-elevator show-sizer></Page>
            </Row>
        </Drawer>
        <Modal v-model="picVisible" title="证书" draggable>
            <img :src="fileUrl" alt="无效的图片链接" style="width: 100%;margin: 0 auto;display: block;">
        </Modal>
    </span>
</template>

<script>
    import {studentEduList} from "@/api/bus";
    import circleLoading from "../../../my-components/circle-loading.vue";

    export default {
        name: "student-manage",
        components: {
            circleLoading,
        },
        data() {
            return {
                edu: false,
                loading: false, // 表单加载状态
                operationLoading: false,
                drop: false,
                selectCount: 0, // 多选计数
                selectList: [], // 多选数据
                dropDownContent: "展开",
                dropDownIcon: "ios-arrow-down",
                picVisible: false,
                fileUrl: '',
                searchForm: {
                    pageNumber: 1, // 当前页数
                    pageSize: 10, // 页面大小
                    sort: "createTime", // 默认排序字段
                    order: "desc", // 默认排序方式
                    userType: "UT_STUDENT",
                    mobile: "",
                    userId: ""
                },
                selectDate: null, //选择日期绑定modal
                columns: [
                    {
                        title: "学校名称",
                        key: "schoolName",
                        width: 130,
                        fixed: "left",
                        align: "center"
                    },
                    {
                        title: "学历",
                        key: "qualifiCations",
                        width: 145,
                        align: "center"
                    },
                    {
                        title: "毕业证书",
                        key: "diplomasImage",
                        width: 180,
                        align: "center",
                        render: (h, params) => {
                            return h("img", {
                                attrs: {
                                    src: params.row.diplomasImage,
                                    alt: "加载图片失败"
                                },
                                style: {
                                    cursor: "pointer",
                                    width: "80px",
                                    height: "60px",
                                    margin: "10px 0",
                                    "object-fit": "contain"
                                },
                                on: {
                                    click: () => {
                                        this.showPic(params.row.diplomasImage);
                                    }
                                }
                            });
                        }
                    },
                    {
                        title: "是否统招",
                        key: "ecTag",
                        width: 120,
                        align: "center",
                        render: (h, params) => {
                            let re = "";
                            if (params.row.ecTag == 0) {
                                return h("div", [
                                    h(
                                        "Tag",
                                        {
                                            props: {
                                                color: "#48CFFA"
                                            }
                                        },
                                        "非统招"
                                    )
                                ]);
                            } else if (params.row.ecTag == 1) {
                                return h("div", [
                                    h(
                                        "Tag",
                                        {
                                            props: {
                                                color: "#32FA4B"
                                            }
                                        },
                                        "统招"
                                    )
                                ]);
                            } else {
                                return h("div", "--");
                            }
                        }
                    },
                    {
                        title: "毕业证书编号",
                        key: "diplomasNum",
                        width: 120,
                        align: "center"
                    },
                    {
                        title: "专业",
                        key: "major",
                        width: 120,
                        align: "center"
                    },
                    {
                        title: "就读开始时间",
                        key: "learnStartTime",
                        width: 115,
                        align: "center"
                    },
                    {
                        title: "就读结束时间",
                        key: "learnEndTime",
                        width: 160,
                        align: "center"
                    },
                    {
                        title: "职称证书",
                        key: "jobImage",
                        width: 180,
                        align: "center",
                        render: (h, params) => {
                            return h("img", {
                                attrs: {
                                    src: params.row.jobImage,
                                    alt: "加载图片失败"
                                },
                                style: {
                                    cursor: "pointer",
                                    width: "80px",
                                    height: "60px",
                                    margin: "10px 0",
                                    "object-fit": "contain"
                                },
                                on: {
                                    click: () => {
                                        this.showPic(params.row.jobImage);
                                    }
                                }
                            });
                        }
                    },
                    {
                        title: "职称名称",
                        key: "jobDescription",
                        width: 130,
                        align: "center"
                    },
                    {
                        title: "职称证书编号",
                        key: "jobDescNum",
                        width: 130,
                        fixed: "right",
                        align: "center"
                    }],
                data: [], // 表单数据
                total: 0 // 表单数据总数
            }
        },
        methods: {
            showPic(v) {
                if(v){
                    this.fileUrl = v;
                    this.picVisible = true;
                }
            },
            showDrawer(params){
                this.edu = true;
                this.searchForm.userId = params;
                this.getDataList();
            },
            getDataList() {
                // 多条件搜索用户列表
                this.loading = true;
                studentEduList(this.searchForm).then(res => {
                    this.loading = false;
                    if (res.status === true) {
                        this.data = res.data.rows;
                        this.total = res.data.total;
                    }
                });
            },
            handleSearch() {
                this.searchForm.pageNumber = 1;
                this.searchForm.pageSize = 10;
                this.getDataList();
            },
            handleReset() {
                this.$refs.searchForm.resetFields();
                this.searchForm.pageNumber = 1;
                this.searchForm.pageSize = 10;
                this.selectDate = null;
                this.username = "";
                this.mobile = "";
                this.company = "";
                this.searchForm.startDate = "";
                this.searchForm.endDate = "";
                // 重新加载数据
                this.getDataList();
            },
            dropDown() {
                if (this.drop) {
                    this.dropDownContent = "展开";
                    this.dropDownIcon = "ios-arrow-down";
                } else {
                    this.dropDownContent = "收起";
                    this.dropDownIcon = "ios-arrow-up";
                }
                this.drop = !this.drop;
            },
            changePage(v) {
                this.searchForm.pageNumber = v;
                this.getDataList();
            },
            changePageSize(v) {
                this.searchForm.pageSize = v;
                this.getDataList();
            },
            changeSort(e) {
                this.searchForm.sort = e.key;
                this.searchForm.order = e.order;
                if (e.order === "normal") {
                    this.searchForm.order = "";
                }
                this.getDataList();
            },
            showSelect(e) {
                this.selectList = e;
                this.selectCount = e.length;
            },
        },
        mounted() {
        }
    }
</script>
